/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/longest-substring-without-repeating-characters
   @Language: C++
   @Datetime: 19-05-16 13:32
   */

class Solution {
public:
	int lengthOfLongestSubstring(string s) {
		vector<int> chars(128,-1);
		int maxlen=0;
		for(int i=-1, j=0; j<s.length(); ++j){
			i=max(i,chars[s[j]]);
			chars[s[j]]=j;
			maxlen=max(maxlen,j-i);
		}
		return maxlen;
	}
};
